<?php


namespace api\web\controller;


use api\web\model\BannerModel;
use api\web\model\NewsModel;
use cmf\controller\RestBaseController;
use think\facade\Db;

class NewsController extends RestBaseController
{
    public function index(){
        $list = NewsModel::select();
        $this->success('院系新闻显示',$list);
    }
    public function getNewsList()
    {
        $keyword = input('keyword',2);
        $where=[];
            if($keyword){
                $where[] = ['title|author','like',"%$keyword"];
            }
        //页码
        $page = input('page/d',1);
        //每页返回的条数
        $pgaeSize = input('page_size/d',10);
        $list = NewsModel::order('list_order','desc')
            ->field('id,title,image,create_time,abstract')
            ->where($where)
            ->page($page,$pgaeSize)
            ->select();
        $this->success('新闻列表',$list);
    }
    public function getNewsInfo()
    {
        $id = input('id/d');
        if(empty($id)){
            $this->error('参数错误');
        }
        $news = NewsModel::withoutField('delete_time,list_order')->find($id);
        if(!$news) {
            $this->error('新闻不存在');
        }
        //第一次处理
        $content1 = htmlspecialchars_decode($news['content']);
        //第二次处理(加true)
        $content2 = cmf_replace_content_file_url($content1, true);
        $this->success('返回成功',$news);
    }
}